using System;
using System.Data.Entity.ModelConfiguration;
using System.Data.Common;
using System.Data.Entity;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using HISModels.Entities;

namespace HISModels.Mapping
{
	public class SysRoleMap : EntityTypeConfiguration<SysRole>
	{
		public SysRoleMap()
		{
			// Primary Key
			this.HasKey(t => t.RoleId);

			// Properties
			this.Property(t => t.DescValue)
				.HasMaxLength(50);
				
			this.Property(t => t.DefaultUrl)
				.HasMaxLength(200);
				
			// Table & Column Mappings
			this.ToTable("SysRoles");
			this.Property(t => t.RoleId).HasColumnName("RoleId");
			this.Property(t => t.DescValue).HasColumnName("DescValue");
			this.Property(t => t.HospitalUnitId).HasColumnName("HospitalUnitId");
			this.Property(t => t.DefaultUrl).HasColumnName("DefaultUrl");

			// Relationships
			this.HasOptional(t => t.RefHu)
				.WithMany(t => t.SysRoles)
				.HasForeignKey(d => d.HospitalUnitId);
				
		}
	}
}

